﻿using System;
using System.Reflection;

namespace Entropy.Ext
{
    public static class ClassResolver
    {
        public static JsClassInfo ResolveClassName(Type type)
        {
            if (type.IsInterface)
            {
                return ResolveInterfaceProxy(type);
            }else
                return null;

        }

        private static JsClassInfo ResolveInterfaceProxy(Type type)
        {
            var attr = type.GetCustomAttribute<JsClassAttribute>(true);
            string className = attr != null ? attr.Name : type.Name.Substring(1);
            string alias = attr != null ? attr.Alias : null;

            return new JsClassInfo {Alias = alias, FullClassName = className};
        }
    }
}